package com.ycz.master.controller;

import com.ycz.master.pojo.Emp;
import com.ycz.master.service.EmpServcie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

/**
 * author zyc
 * Created on 2021/9/28 13:38
 */
@Controller
public class IndexController {
    @Autowired
    private EmpServcie empServcie;

    @RequestMapping("/")
    public String index(){
//        return "view/index";
        return "login";
    }
    @RequestMapping("/login")
    public String login(@RequestParam String account,
                        @RequestParam String password,
                        HttpServletRequest request,
                        Model model){
        Emp login = empServcie.login(account, password);
        if(login!=null){
            request.getSession().setAttribute("login",login);
            return "redirect:jump?url=view/index.html";
        }
       else {
           model.addAttribute("msg","用户名或密码错误");
           return "login";
        }
    }
}
